replace_substrs_vec <- function(raw_vec = c(), removepat = c(), 
                                replace_vec = rep("", length(removepat))){
  library(stringr)
  for(i in 1:length(raw_vec)){
    for(j in 1:length(removepat)){
      if(length(grep(x = raw_vec[i], pattern = removepat[j])) >= 1){
        raw_vec[i] <- str_replace_all(string = raw_vec[i], pattern = removepat[j], 
                                  replacement = replace_vec[j])
      }
    }
  }
  return(raw_vec)
}


replace_substrs_df <- function(raw_df = data.frame(), removepat = c(), 
                               replace_vec = rep("", length(removepat))){
  for(i in 1:dim(raw_df)[2]){
    raw_df[,c(i)] <- replace_substrs_vec(raw_vec = raw_df[,c(i)],
                                         removepat = removepat, 
                                         replace_vec = replace_vec)
  }
  return(raw_df)
}



#### TEST AREA ####
# raw_vec <- c(
#   "woshini baba 1",
#   "nishiwo mama 2",
#   "nishiwosunzi 66",
#   "wosunzi shini"
# )
# 
# removepat <- c(
#   " \\d",
#   "wosunzi"
# )
# 
# replace_vec <- c(
#   "空格数字",
#   ""
# )
# 
# 
# replace_substrs_vec(raw_vec, removepat, replace_vec)
# replace_substrs_vec(raw_vec, removepat)
# replace_substrs_df(
#   raw_df = data.frame(
#     "v1" = c("abc", "bcd", "ced"),
#     "v2" = c("abc", "bcbd", "ced"),
#     "v3" = c("abc", "bcd", "aced")
#   ),
#   removepat = c("a", "b"),
#   replace_vec = c("啊", "波")
# )
